<?php
    session_start();
    if(!isset($_SESSION['loggedin'])) header('Location: index.php');
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="../../assets/ico/favicon.ico">

    <title>TestYourSelf - Start</title>

    <!-- Bootstrap core CSS -->
    <link href="../../bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/select.css" rel="stylesheet">
    <link href="css/template.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>

<div class="site-wrapper">

    <div class="site-wrapper-inner">

        <div class="cover-container">

            <div class="masthead clearfix">
                <div class="inner">
                    <h3 class="masthead-brand">TestYourSelf</h3>
                    <ul class="nav masthead-nav">
                        <li class="active"><a href="#">Start</a></li>
                        <li><a href="highscore.php">Highscore</a></li>
                        <li><a href="profil.php">Profil</a></li>
                        <li><a href="logout.php">Logout</a></li>
                        <?php if(isset($_SESSION['isadmin']) && $_SESSION['isadmin']=="true"){ ?>
                        <li><a href="admin.php">Administration</a></li>
                        <?php } ?>
                    </ul>
                </div>
            </div>


            <div class="inner cover">
                <h1 class="cover-heading">
                    <?php
                         if(!empty($_POST['scenario'])){
                            echo 'Kategorie auswählen';
                         }
                         elseif(!empty($_POST['category'])){
                            list($category_id, $category_name) = explode("-", $_POST['category'], 2);
                            echo 'Kategorie: "'.$category_name.'"';
                         }
                         else{
                            echo 'Szenario auswählen';
                         }
                    ?>
                </h1>

                <?php
                if(!empty($_POST['scenario'])){
                ?>
                    <form class="form-select" role="form" action="select.php" method="post">
                        <select name="category" class="form-control" size="5">
                            <?php
                                $jsonurl = "http://localhost:8080/TestYourselfASE/rest/categories/".$_POST['scenario'];
                                $jsonfile = file_get_contents($jsonurl);
                                $json = json_decode($jsonfile);
                                foreach($json as $obj){
                                   echo '<option value="'.$obj->Id.'-'.$obj->Name.'">'.$obj->Name.'</option>';
                                }

                            ?>
                        </select>
                        <input type="hidden" name="selectedscenario" value=<?php echo '"'.$_POST['scenario'].'"' ?> >
                        <button class="btn btn-lg btn-primary btn-block" type="submit">Auswählen</button>
                    </form>

                <?php }elseif(!empty($_POST['category'])){ ?>

                                <form class="form-select" role="form" action="quiz.php" method="post">
                                    <div>Schwierigkeitsgrad wählen:</div>
                                    <select name="severity" class="form-control" size="4">

                                        <?php
                                            list($category_id, $category_name) = explode("-", $_POST['category'], 2);
                                            $jsonurl = "http://localhost:8080/TestYourselfASE/rest/severity/".$category_id;
                                            $jsonfile = file_get_contents($jsonurl);
                                            $json = json_decode($jsonfile);
                                            echo '<option value="0-'.$category_id.'">Zufällig gemischt</option>';
                                            foreach($json as $obj){
                                                if ($obj->Severity == "1") echo '<option value="1-'.$category_id.'">Leicht</option>';
                                                elseif ($obj->Severity == "2")     echo '<option value="2-'.$category_id.'">Mittel</option>';
                                                else echo '<option value="3-'.$category_id.'">Schwer</option>';
                                            }

                                        ?>
                                    </select>
                                    <input type="hidden" name="scenario" value=<?php echo '"'.$_POST['selectedscenario'].'"' ?> >
                                    <button class="btn btn-lg btn-primary btn-block" type="submit">Auswählen</button>
                                </form>

                <?php }else{  ?>

                            <form class="form-select" role="form" action="select.php" method="post">
                                <select name="scenario" class="form-control" size="5">
                                    <?php
                                        $jsonurl = "http://localhost:8080/TestYourselfASE/rest/scenarios";
                                        $jsonfile = file_get_contents($jsonurl);
                                        $json = json_decode($jsonfile);
                                        foreach($json as $obj){
                                           echo '<option value="'.$obj->Id.'">'.$obj->Name.'</option>';
                                        }

                                    ?>
                                </select>
                                <button class="btn btn-lg btn-primary btn-block" type="submit">Auswählen</button>
                            </form>
                <?php  }   ?>

            </div>

            <div class="mastfoot">
                            <div class="inner">
                                <p>by Christoph Schuster, Martin Schmied, Thomas Stoellner, Philipp Taeubel</p>
                            </div>
                        </div>

        </div>

    </div>

</div>

<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="../../bootstrap/js/bootstrap.min.js"></script>
</body>
</html>

